package com.kfh.ybracelet.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.kfh.ybracelet.R;
import com.kfh.ybracelet.bean.MyResult;
import com.kfh.ybracelet.utils.CommonUtils;
import com.kfh.ybracelet.widget.CircleImageView;

import java.util.List;

/**
 * 我的模块  孩子列表的adapter
 * Created by Aaron on 15/8/11.
 */
public class MyBabyAdapter extends BaseAdapter {

    private List<MyResult.MyData> tempList;
    private Context ctx;

    public MyBabyAdapter(Context ctx, List<MyResult.MyData> tempList) {
        this.ctx = ctx;
        this.tempList = tempList;
    }

    public void setData(List<MyResult.MyData> tempList) {
        this.tempList = tempList;
    }

    @Override
    public int getCount() {
        return tempList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_my_baby, null);
            viewHolder = new ViewHolder();
            viewHolder.iv_head_pic = (CircleImageView) convertView.findViewById(R.id.iv_head_pic);
            viewHolder.tv_my_name = (TextView) convertView.findViewById(R.id.tv_my_name);
            viewHolder.tv_watch_tel = (TextView) convertView.findViewById(R.id.tv_watch_tel);
//            viewHolder.tv_attention_people = (TextView) convertView.findViewById(R.id.tv_attention_people);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Glide.with(ctx)
                .load(tempList.get(position).picUrl)
                .dontAnimate().diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter()
                .placeholder(R.mipmap.temp_pic).into(viewHolder.iv_head_pic);



        viewHolder.tv_my_name.setText(tempList.get(position).nickName);
//        viewHolder.tv_attention_people.setText(tempList.get(position).classInfo);


        if (!CommonUtils.isNull(tempList.get(position).phoneNum) && tempList.get(position).phoneNum.length() >= 3) {

//            String substring = tempList.get(position).phoneNum.substring(0, 3);

//            viewHolder.tv_watch_tel.setText(tempList.get(position).phoneNum.substring(0, 3) + "********");
            viewHolder.tv_watch_tel.setText(tempList.get(position).phoneNum);
        } else {
            viewHolder.tv_watch_tel.setText("暂未绑定");
        }

        return convertView;
    }

    private class ViewHolder {

        private TextView tv_my_name;
        private TextView tv_watch_tel;
        //        private TextView tv_attention_people;
        private CircleImageView iv_head_pic;

    }
}
